package com.example.mvvmdemo.home.data;

import androidx.lifecycle.ViewModel;
import androidx.paging.Pager;
import androidx.paging.PagingConfig;
import androidx.paging.PagingData;
import androidx.paging.rxjava2.PagingRx;

import com.example.httplibrary.bean.ResultBean;
import com.example.mvvmdemo.home.api.DeviceApiService;
import com.example.mvvmdemo.home.paging.DeviceExceptionBean;
import com.example.mvvmdemo.home.paging.ExamplePagingSource;

import io.reactivex.Flowable;
import io.reactivex.Single;

/**
 * created by tl
 * created at 2020/8/12
 * 获取原始数据仓库
 */
public class MainRepository {
    private DeviceApiService deviceApiService;

    public MainRepository(DeviceApiService deviceApiService) {
        this.deviceApiService = deviceApiService;
    }

    public Flowable<PagingData<DeviceExceptionBean.ContentBean>> getDeviceData() {
        Pager<Integer, DeviceExceptionBean.ContentBean> pager = new Pager<Integer, DeviceExceptionBean.ContentBean>(
                new PagingConfig(20), () -> new ExamplePagingSource(deviceApiService));

        return PagingRx.getFlowable(pager);
    }
}
